Class IOAid
static var shakeData;
static var doShake;
static var doSetRes;
static function setRes(path,doBack){
	Me.doSetRes=doBack;
	IO.resPath=path;
	var script=document.createElement("script");
	document.body.appendChild(script);
	script.onload=Me.setRes2;
	script.src=path+"@.js?"+G.config.version;
}
static function setRes2(evt){
	document.body.removeChild(evt.target);
	var arr=t;
	IO.resHash={};
	IO.resFrameHash={};
	for(var i=0;i<arr.length;i++){
		var str=arr[i];
		var a=str.split(",");
		var k=a[0];
		for(var j=2;j<a.length;j++){
			a[j]=int(a[j]);
		}
		IO.resHash[k]=a;
		var n=k.lastIndexOf(".");
		var f=int(k.slice(n+1));
		if(f>0){
			var k2=k.slice(0,n);
			if(IO.resFrameHash[k2]==null) IO.resFrameHash[k2]=G.max;
			IO.resFrameHash[k2]=Math.min(IO.resFrameHash[k2],f);
		}
	}
	call(Me.doSetRes);
}
static function viewImage(urls,index){
	if(G.platform==2){
		if(!window.WeixinJSBridge){
			G.stage.setEnabled(false);
			callLater([Me.viewImage,urls,index],500);
			return;
		}
		G.stage.setEnabled(true);
		for(var i=0;i<urls.length;i++){
			var url=urls[i];
			if(url.indexOf("http:")!=0&&url.indexOf("file:")!=0){
				url=G.path+url;
			}
			urls[i]=url;
		}
		WeixinJSBridge.invoke("imagePreview",{
			current:urls[index],
			urls:urls
		});
		return;
	}
	var slideBar=G.stage.addChild(SlideBar);
	slideBar.setSize("f","f");
	slideBar.setBg("#000");
	slideBar.dotBox.setVisible(false);
	for(var i=0;i<urls.length;i++){
		var url=urls[i];
		slideBar.addChild([
			[{w:"f",h:"f"},
				[Img,{pos:["c","c"],loadSrc:url,loadSize:[G.w,G.h,true]}]
			]
		]);
	}
	slideBar.index=index;
}
static function getUrlParam(key){
	var s=unescape(document.URL);
	var n=s.indexOf("#"+key+"=");
	if(n==-1) n=s.indexOf("&"+key+"=");
	if(n==-1) return null;
	s=s.slice(n+key.length+2);
	n=s.indexOf("#");
	if(n==-1) n=s.indexOf("&");
	if(n>-1) s=s.slice(0,n);
	return s;
}
static function getGeolocation(doBack){
	Me.doGeoBack=doBack;
	var geo=navigator["geolocation"];
	geo["getCurrentPosition"](Me.getGeolocation2,Me.getGeolocation3);
}
static function getGeolocation2(position){
	call(Me.doGeoBack,position);
}
static function getGeolocation3(error){
	call(Me.doGeoBack);
}
static function shakeBack(doShake){
	Me.doShake=doShake;
	window.ondevicemotion=!doShake?null:Me.shakeBack2;
}
static function shakeBack2(evt){
	if(!Me.doShake){
		window.ondevicemotion=null;
		return;
	}
    var acc=evt.accelerationIncludingGravity;
	if(!Me.shakeData){
		Me.shakeData={x:acc.x,y:acc.y,z:acc.z,time:G.now};
	}
	var data=Me.shakeData;
    var timeDiff=G.now-data.time;
    if(timeDiff<10) return;
    data.time=G.now;
    var speed=(Math.abs(acc.x-data.x)+Math.abs(acc.y-data.y)+Math.abs(acc.z-data.z))/timeDiff*10000;
    data.x=acc.x;
    data.y=acc.y;
    data.z=acc.z;
    if(speed<10000) return;
	Me.shakeData.time=G.now+1000;
	var caller=Me.doShake;
	if(caller.__isBox&&!caller.stage){
		Me.doShake=null;
		return;
	}
	call(Me.doShake);
}
static function getCookie(name){
	var reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	var arr=document.cookie.match(reg)
	if(arr) return unescape(arr[2]);
	return null;
}
static function setCookie(name,value){
	var d=new Date();
	d.setTime(d.getTime()+30*24*60*60*1000);
	document.cookie=name+"="+escape(value)+";expires="+d.toGMTString();
}
static function setStorage(name,value){
	if(value==null){
		window.localStorage.removeItem(name);
		return;
	}
	if(is(Number,value)){
		value+="";
	}
	else if(!is(String,value)){
		value=enjson(value);
	}
	window.localStorage[name]=value;
}